#ifndef __JSONRPC_H__
#define __JSONRPC_H__

#include <glib.h>
#include "json/json.h"

#ifdef __cplusplus
extern "C" {
#endif

#define JSONRPC_PARSE_ERROR -32700
#define JSONRPC_INVALID_REQUEST -32600
#define JSONRPC_METHOD_NOT_FOUND -32601
#define JSONRPC_INVALID_PARAMS -32602
#define JSONRPC_INTERNAL_ERROR -32603

typedef struct {
	GList *methods;
} jsonrpc_server;

typedef json_object* (*jsonrpc_method_ptr)(json_object *);

typedef struct {
	char *name;
	jsonrpc_method_ptr method;
} jsonrpc_method;

void jsonrpc_init(jsonrpc_server *server);
void jsonrpc_destroy(jsonrpc_server *server);

void jsonrpc_register_method(jsonrpc_server *server, jsonrpc_method_ptr method, const char *name);
void jsonrpc_deregister_method(jsonrpc_server *server, const char *name);

json_object *jsonrpc_invoke(jsonrpc_server *server, const char *json);

#ifdef __cplusplus
}
#endif

#endif
